<?php
declare (strict_types = 1);
namespace app\index\controller;
use app\common\controller\Base;
use app\common\model\Example;

class Index extends Base
{
	public function index() : string
	{
		return 'Hello.';
	}


	/**
	 * 测试 - 批量写入
	 */
	public function test_insert()
	{
		$Example = new Example();

		$timestamp = time();
		$data = [
			[
				'name' => 'aaa',
				'gender' => 0,
				'age' => 33,
				'create_time' => $timestamp
			],
			[
				'name' => 'bbb',
				'gender' => 0,
				'age' => 33,
				'create_time' => $timestamp
			],
			[
				'name' => 'ccc',
				'gender' => 0,
				'age' => 33,
				'create_time' => $timestamp
			],
		];
		$save = $Example->saveAll($data);
		$res_str = $save ? '成功' : '失败';
		echo "批量写入数据{$res_str}";

		$params_data_list = [
			'where' => [
				['usable', '=', 1]
			],
			'field' => [
				'name',
				'gender',
				'age'
			]
		];
		$data_list = $Example
			->validate(true)
			->getDataList($params_data_list);
		dump($data_list);

	}


	/**
	 * 测试 - 查询
	 */
	public function test_select()
	{
		$Example = new Example();

		$params_data_list = [
			'where' => [
				['usable', '=', 1]
			],
			'field' => [
				'name',
				'gender',
				'age'
			]
		];
		$data_list = $Example
			->validate(true)
			->getDataList($params_data_list);
		dump($data_list);

		Base::saveLog(2, 'QWE');
	}


}
